package com.espeaker.sdk.api;

import android.os.Handler;

import com.espeaker.sdk.ESpeakerParameters;
import com.espeaker.sdk.Constants;
import com.espeaker.sdk.utils.Base64Util;

public class LoginApi extends MiaoApi {
	/*
	 * 用户登录
	 */
	public void userLogin(final String username, final String password, final Handler handler) {
		new Thread() {
			@Override
			public void run() {
				try {
					String encodePassword = Base64Util.encodeStr(password);
					encodePassword = Base64Util.encodeStr(encodePassword);
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("username", username,true);
					params.add("password", encodePassword,true);
					String mRes = request(MiaoApi.GetBaseURL(), USER_LOGIN, params);
					if (handler != null) {
						handler.obtainMessage(Constants.LOGINAPI_LOGININ, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
	public void changePass(final String userName,final String oldPass,final String newPass,final Handler handler)
	{
		new Thread() {
			@Override
			public void run() {
				try {
					String oldPassStr = Base64Util.encodeStr(oldPass);
					oldPassStr = Base64Util.encodeStr(oldPassStr);
					
					String newPassStr = Base64Util.encodeStr(newPass);
					newPassStr = Base64Util.encodeStr(newPassStr);
					
					ESpeakerParameters params = new ESpeakerParameters();
					params.add("username", userName,true);
					params.add("password", oldPassStr,true);
					params.add("reset_password", newPassStr,true);
					String mRes = request(MiaoApi.GetBaseURL(), USER_CHANGE_PASS, params);
					if (handler != null) {
						handler.obtainMessage(Constants.USER_CHANGE_PASS, mRes).sendToTarget();
					}
				} catch (Exception er) {
				}
			}
		}.start();
	}
}
